home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / irix / scripts / movetree < prev    next >
Encoding:
Text File  |  1994-08-02  |  2.5 KB  |  92 lines

  1. #! /bin/csh -f
  2. #
  3. # $Id: movetree,v 1.5 1994/02/22 21:49:46 carlson Exp $
  4. #
  5. # movetree    Move a directory tree from one file system to another.
  6. #
  7. # Synopsis:
  8. #    movetree [-v] [-n] <source-full-path> [<destination-full-path>]
  9. #
  10. # Where:
  11. #    -v            Use v option on tar.
  12. #    -n            Don't delete the source when done.
  13. #    <source-full-path>    The full path of the top source directory
  14. #                to move.
  15. #    <destination-full-path>    The full path of the destination directory
  16. #                into which to move.  If the directory
  17. #                doesn't exist, it is created.  If this
  18. #                option is not provided, . is assumed.
  19. #
  20. # Revision History:
  21. #    $Log: movetree,v $
  22. # Revision 1.5  1994/02/22  21:49:46  carlson
  23. # Added 'p' flag to tar command.  This restores files to their original
  24. #   modes and ignores the present umask.
  25. #
  26. # Revision 1.4  1993/08/20  13:13:30  carlson
  27. # Added better usage info.
  28. # Added B option to tar commands.
  29. # Used $options in tar command.
  30. # If a problem occurs or -n specified, don't remove original directory.
  31. #
  32. # Revision 1.3  93/01/22  12:33:33  carlson
  33. # Modified to have an option that will not remove the source directory
  34. #   when completed.
  35. # Revision 1.2  92/01/22  15:22:35  carlson
  36. # Added RCS symbols.
  37. # If no parameters passed, print a quick help message.
  38. #-------------------------------------------------------------------------
  39.  
  40. if ( "$1" == "" ) then
  41.     echo "Usage: movetree [-v] [-n] <source-path> [<destination-path>]"
  42.     echo "   -v                  Use v option on tar."
  43.     echo "   -n                  Don't delete the source when done."
  44.     echo "   <source-path>       Is the full path to the directory to be"
  45.     echo "                       moved."
  46.     echo "   <destination-path>  Is the path to the directory where the"
  47.     echo "                       source directory is to be moved.  If not"
  48.     echo "                       provided, assumes the current directory."
  49.     exit 0
  50. endif
  51.  
  52. set options = "xpBRf"
  53. set remove = 1
  54.  
  55. set argv = `getopt nv $*`
  56. while ( "$1" != "--" )
  57.     switch ( $1 )
  58.       case "-n":
  59.     set remove = 0
  60.     shift
  61.     breaksw
  62.       case "-v":
  63.     set options = "xvpBRf"
  64.     shift
  65.     breaksw
  66.     endsw
  67. end
  68. shift
  69.  
  70. set srcdir = $1:h
  71. set srcfil = $1:t
  72.  
  73. set fixdd = 0
  74. if ( "$2" == "" ) then
  75.     set dstdir = `pwd`
  76. else
  77.     set dstdir = $2
  78.     if ( ! -e $dstdir ) then
  79.     set dstdir = $2:h
  80.     set fixdd = 1
  81.     endif
  82. endif
  83.  
  84. (cd $srcdir ; tar cBf - $srcfil) | (cd $dstdir ; tar $options -)
  85. set problem = $status
  86.  
  87. if ( $fixdd ) mv $dstdir/$srcfil $2
  88.  
  89. if ( $problem == 0 && $remove == 1 ) rm -rf $1
  90.